package fanxing.demo01;

/**
 * @author Mr.ma
 * @since 2022/10/25 14:05
 **/
public class Test01 {
    public static void main(String[] args) {
        Info<Integer> integerInfo = new Info<>(1,2);
        System.out.println("integerInfo = " + integerInfo);
        Info<String> stringInfo = new Info<>("hello","world");
        System.out.println("stringInfo = " + stringInfo);
    }
}

/**
 * 实体类，用于学习定义泛型类
 * 该类中的参数类型为T，即为泛型
 * 本类在定义时无法确定类中参数的数据类型
 * 使用泛型相较于Object来说，可以保证类中参数类型为统一类型
 * 泛型在创建实例时，按需进行匹配调用
 * @param <T>
 */
class Info<T>{
    private T pro01;
    private T pro02;

    public Info() {
    }

    public Info(T pro01, T pro02) {
        this.pro01 = pro01;
        this.pro02 = pro02;
    }

    public T getPro01() {
        return pro01;
    }

    public void setPro01(T pro01) {
        this.pro01 = pro01;
    }

    public T getPro02() {
        return pro02;
    }

    public void setPro02(T pro02) {
        this.pro02 = pro02;
    }

    @Override
    public String toString() {
        return "info{" +
                "pro01=" + pro01 +
                ", pro02=" + pro02 +
                '}';
    }
}
